package io;

import java.io.File;
import java.rmi.Naming;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import interfaces.IServicioProducto;
import interfaces.IServicioProveedor;
import dto.DTOListaDePrecios;


public class ImportListaPrecios {
	
	private IServicioProveedor srvProveedor;
	private IServicioProducto srvProducto;
	
	public DTOListaDePrecios importar(String url)
	{
		
		try {
			
			String razonsocial;
			Integer codigo;
			srvProveedor = (IServicioProveedor)Naming.lookup("//localhost/ServicioProveedor");
			srvProducto= (IServicioProducto)Naming.lookup("//localhost/ServicioProducto");
			
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            Document doc = docBuilder.parse (new File("d:\\lista de precios.xml"));
            
            doc.getDocumentElement ().normalize();
           // System.out.println ("Root element of the doc is " + 
           //doc.getDocumentElement().getNodeName());
            
            Element rz = (Element) doc.getElementsByTagName("razonsocial");
            /*
            NodeList listOfPersons = doc.getElementsByTagName("razonsocial");
            int totalPersons = listOfPersons.getLength();
            System.out.println("Total no of people : " + totalPersons);

            for(int s=0; s<listOfPersons.getLength() ; s++){


                Node firstPersonNode = listOfPersons.item(s);
                if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){


                    Element firstPersonElement = (Element)firstPersonNode;

                    //-------
                    NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                    Element firstNameElement = (Element)firstNameList.item(0);

                    NodeList textFNList = firstNameElement.getChildNodes();
                    System.out.println("First Name : " + 
                           ((Node)textFNList.item(0)).getNodeValue().trim());

                    //-------
                    NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                    Element lastNameElement = (Element)lastNameList.item(0);

                    NodeList textLNList = lastNameElement.getChildNodes();
                    System.out.println("Last Name : " + 
                           ((Node)textLNList.item(0)).getNodeValue().trim());

                    //----
                    NodeList ageList = firstPersonElement.getElementsByTagName("age");
                    Element ageElement = (Element)ageList.item(0);

                    NodeList textAgeList = ageElement.getChildNodes();
                    System.out.println("Age : " + 
                           ((Node)textAgeList.item(0)).getNodeValue().trim());

                    //------


                }//end of if clause


            }//end of for loop with s var
            */
            

		} catch (Exception e) {
			// TODO: handle exception
		}
		
		
		return null;
	}

}
